package ArrayListDemo;

import java.util.ArrayList;

public class demo3 {
    public static void main(String[] args) {
        ArrayList<Users> list = new ArrayList<>();
        list.add(new Users(1,"张三","123"));
        list.add(new Users(2,"李四","456"));
        list.add(new Users(3,"王五","789"));
        //用户登录
        Users user = new Users(1,"张三","123");
        boolean flag = userExist(list, user.getId());
        if(!flag){
            System.out.println("登录成功");
        }else{
            System.out.println("登录失败，"+"存在相同id-"+user.getId());
        }
    }
    public static boolean userExist(ArrayList<Users> list, int id) {
        for (Users user : list) {
            if(user.getId()==id){
                return true;
            }
        }
        return false;
    }
}
